<?php
/**
 * Created by PhpStorm.
 * User: moquan
 * Date: 2018/7/11
 * Time: 19:02
 */

namespace app\lib\wx;


use think\Exception;

class Menu extends Application {
    const API_CREATE = 'https://api.weixin.qq.com/cgi-bin/menu/create?access_token=%s';

    public function add( $buttonArr ){
        $url = sprintf(self::API_CREATE, $this->accessToken );
        $res = json_decode( curl_post( $url, $buttonArr ), true );
        if ( $res['errmsg'] != 'ok' ) {
            $err = json_encode( $res, JSON_UNESCAPED_UNICODE );
            $this->recordErrorLog( $err );
            throw new Exception( 'Request WeChat Menu fail. response: '.$err );
        }
        return $res;
    }
}